import { createStore } from 'vuex'
import vuexp from 'vuex-persistedstate'
import { ElMessage } from 'element-plus'
import router from 'vue-router'
export default createStore({
  state: {
    token:localStorage.getItem("token") || '',
    indexlist:[],
    flag:true,
    column:'',
    author:'',
  },
  getters: {
  },
  mutations: {
    //我的专栏id
    userid(state,obj){
      state.column =obj.column
      state.author =obj.id
    },
    flag(state){
      state.flag =!state.flag
    },
    //首页数据
    indexlist(state,payload){
       console.log(payload)
       state.indexlist =payload
    },
    //获取token
    gettoken(state,payload) {
      state.token =payload
     },
     goout(state){
       state.token =''
       localStorage.removeItem("token")
       ElMessage({
        showClose: true,
        message: '退出成功',
        type: 'success',
      })
      // route
     }
  },
  actions: {
    token({commit},obj){
      ElMessage({
        showClose: true,
        message: '登录成功,2秒后进行操作',
        type: 'success',
      })
      setTimeout(()=>{
        commit('gettoken',obj)
      },2000)
      
    }
  },
  modules: {
  },
  plugins:[vuexp()]
})
